﻿using System.ComponentModel;
using System.Globalization;
using System.Threading;

namespace JanusLibAing.Threading
{
    public static class LanguageHelper
    {
        /// <summary>
        /// Start Backgroundworker with language supporting
        /// </summary>
        /// <param name="threadForRun">The thread for run.</param>
        public static void StartThread(BackgroundWorker threadForRun)
        {
            CultureInfo cultureInfo = Thread.CurrentThread.CurrentUICulture;
            threadForRun.RunWorkerAsync(cultureInfo);
        }

        /// <summary>
        /// Init Backgroundworker thread
        /// use as first call in DoWork handler
        /// </summary>
        /// <param name="e">The <see cref="System.ComponentModel.DoWorkEventArgs"/> instance containing the event data.</param>
        public static void InitThread(DoWorkEventArgs e)
        {
            if (e.Argument != null && e.Argument is CultureInfo)
            {
                Thread.CurrentThread.CurrentUICulture = (CultureInfo)e.Argument;
            }
        }
    }
}
